package com.sangmo.fts.process.inventory.model;

import com.sangmo.boot.framework.data.entity.general.SoftDeleteEntity;
import com.sangmo.boot.framework.data.json.meta.ExtView;
import com.sangmo.boot.framework.data.json.meta.One;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataField;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataView;
import com.sangmo.fts.basic.model.Company;
import com.sangmo.fts.common.IConstants;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;

@Entity
@Table(name = "if_inbound")
@DataView
@ExtView
@SQLDelete(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@SQLDeleteAll(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@Where(
        clause = "deleted = 0"
)
public class IfInbound extends SoftDeleteEntity {

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long trainingId;

    @DataField(value = IConstants.DATA_TYPE.STRING_10, index = true, unique = true)
    private String code;

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long outboundId;

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long billId;

//    @One("")
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long loanId;

    /**
     * 质权人 （银行）
     */
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    @One(value = "pledgeeCompany", target = Company.class, fieldset = {"id","name"})
    private Long pledgee;

    /**
     * 出质人 （卖方）
     */
    @One(value = "pledgorCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long pledgor;

    /**
     * 监管方 （仓储企业）
     */
    @One(value = "regulatorCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long regulator;

    @DataField(value = IConstants.IF_INBOUND_DATA_TYPE.INBOUND_STATE, required = true, index = true)
    private String state = States.DISPATCHED;

    private Date inDate;

    private Long confirmedBy;

    public Long getTrainingId() {
        return trainingId;
    }

    public void setTrainingId(Long trainingId) {
        this.trainingId = trainingId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Long getOutboundId() {
        return outboundId;
    }

    public void setOutboundId(Long outboundId) {
        this.outboundId = outboundId;
    }

    public Long getBillId() {
        return billId;
    }

    public void setBillId(Long billId) {
        this.billId = billId;
    }

    public Long getLoanId() {
        return loanId;
    }

    public void setLoanId(Long loanId) {
        this.loanId = loanId;
    }

    public Long getPledgor() {
        return pledgor;
    }

    public void setPledgor(Long pledgor) {
        this.pledgor = pledgor;
    }

    public Long getPledgee() {
        return pledgee;
    }

    public void setPledgee(Long pledgee) {
        this.pledgee = pledgee;
    }

    public Long getRegulator() {
        return regulator;
    }

    public void setRegulator(Long regulator) {
        this.regulator = regulator;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public Date getInDate() {
        return inDate;
    }

    public void setInDate(Date inDate) {
        this.inDate = inDate;
    }

    public Long getConfirmedBy() {
        return confirmedBy;
    }

    public void setConfirmedBy(Long confirmedBy) {
        this.confirmedBy = confirmedBy;
    }

    public interface States {
        String DISPATCHED = "DISPATCHED"; //待收货
        String PENDING = "PENDING"; //待入库
        String COMPLETED = "COMPLETED"; //已入库
    }
}
